package com.sky.service.impl;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.entity.Category;
import com.sky.mapper.CategoryMapper;
import com.sky.result.PageResult;
import com.sky.service.CategoyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class CategoryServiceImpl implements CategoyService {

   @Autowired
    private CategoryMapper categoryMapper;

    /**
     * 条件分类分页查询
     */
    @Override
    public PageResult pageQuery(CategoryPageQueryDTO categoryPageQueryDTO) {
        PageHelper.startPage(categoryPageQueryDTO.getPage(),categoryPageQueryDTO.getPageSize());
        List<Category> categories =  categoryMapper.pageQuery(categoryPageQueryDTO);
        Page<Category> p =(Page<Category> )categories;

        log.info("分页查询分类信息：{}", p.getResult());
        log.info("总数据：{}", p.getTotal());
        return new PageResult(p.getTotal(), p.getResult());
    }




    /**
     * 根据id修改分类
     */
    @Override
    public void update(Category category) {
        log.info("修改分类：{}",category);
        categoryMapper.update(category);

    }
    /**
     * 新增分类
     */
    @Override
    public void save(Category category) {
        log.info("新增分类：{}",category);
        categoryMapper.insert(category);

    }
    /**
     * 启用，禁用分类
     */
    @Override
    public void startOrStop(Integer status, Long id) {
        log.info("启用，禁用分类：{}",id);
        categoryMapper.startOrStop(status,id);
    }

    /**
     * 根据类型查询分类
     */
    @Override
    public List<Category> list(Integer type) {
        return categoryMapper.list(type);

    }
    /**
     * 删除分类
     */
    @Override
    public void delete(Long id) {
        categoryMapper.delete(id);

    }



}
